package com.bjsxt.controller;

import com.bjsxt.disruptor.*;
import com.lmax.disruptor.EventHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.TreeMap;

/**
 * @Description:
 * @ClassName: MatchController
 * @Author: chenyu
 * @Date: 2025/3/20 15:19
 */
@RestController
public class MatchController {

    @Autowired
    private EventHandler<OrderEvent>[] eventHandlers;


    @GetMapping("/match/order")
    public TreeMap<BigDecimal, MergeOrder> getTradeData(@RequestParam(required = true) String symbol, @RequestParam(required = true)Integer orderDirection) {
        for (EventHandler<OrderEvent> eventHandler : eventHandlers) {
            OrderMatchDisruptorHandler orderEventHandler = (OrderMatchDisruptorHandler) eventHandler;
            if (orderEventHandler.getSymbol().equals(symbol)) {
                OrderBooks orderBooks = orderEventHandler.getOrderBooks();
                return orderBooks.getCurrentOrders(OrderDirection.getOrderDirection(orderDirection));
            }
        }
        return null;
    }
}
